package abc.database.Interceptor;

import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class SqlInterceptorFactory implements ISqlInterceptorFactory {
    @Autowired(required = false)
    InnerInterceptor sqlInterceptor;

    List<InnerInterceptor> interceptors = new ArrayList<>();

    @PostConstruct
    void init() {
        if(sqlInterceptor != null) {
            interceptors.add(sqlInterceptor);
        }
    }

    @Override
    public List<InnerInterceptor> getInterceptors() {
        return interceptors;
    }

    @Override
    public <T extends InnerInterceptor> void add(T interceptor) {
        interceptors.add(interceptor);
    }
}
